home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / alarms.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  3KB  |  134 lines

  1. /* --------------------------------- alarms.c ------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Set and show alarms/warnings/status the Head Up Display. It also arms
  8.  * the warning lamps.
  9. */
  10.  
  11. #include "plane.h"
  12.  
  13.  
  14. LOCAL_FUNC void NEAR show_xbreak (HUD *h, OBJECT *p, int color);
  15.  
  16. extern void FAR
  17. alarm_set (int mode)
  18. {
  19.     if (!st.quiet)
  20.         return;
  21.  
  22.     if ((mode & SS_ALARM) && !(st.sounds & SS_ALARM)) {
  23.         st.sounds |= SS_ALARM;
  24.         Snd->Effect (EFF_ALARM, SND_ON);
  25.     } else if (!(mode & SS_ALARM) && (st.sounds & SS_ALARM)) {
  26.         st.sounds &= ~SS_ALARM;
  27.         Snd->Effect (EFF_ALARM, SND_OFF);
  28.     }
  29.  
  30.     if ((mode & SS_WARN) && !(st.sounds & SS_WARN)) {
  31.         st.sounds |= SS_WARN;
  32.         Snd->Effect (EFF_WARN, SND_ON);
  33.     } else if (!(mode & SS_WARN) && (st.sounds & SS_WARN)) {
  34.         st.sounds &= ~SS_WARN;
  35.         Snd->Effect (EFF_WARN, SND_OFF);
  36.     }
  37. }
  38.  
  39. LOCAL_FUNC void NEAR
  40. show_xbreak (HUD *h, OBJECT *p, int color)
  41. {
  42.     int    dx, dy, x, y;
  43.  
  44.     dy = h->sy>>1;
  45.     dx = h->sx>>1;
  46.     y = h->orgy + h->shifty - h->sy + dy;
  47.  
  48.     if ((EX->hud3 & HUD_XVAR) && (int)EX->misc[17] > 0)
  49.         x = fmul (h->sx>>1, (int)EX->misc[17]);
  50.     else
  51.         x = 0;
  52.  
  53.     if (x > 0 || ((Uint)st.present) % 400 < 200) {    /* blink rate: 2.5Hz */
  54.         gr_color (color);
  55.         gr_move (h->orgx-x-dx, y-dy);
  56.         gr_draw (h->orgx-x,    y);
  57.         gr_draw (h->orgx-x-dx, y+dy);
  58.  
  59.         gr_move (h->orgx+x+dx, y-dy);
  60.         gr_draw (h->orgx+x,    y);
  61.         gr_draw (h->orgx+x+dx, y+dy);
  62.     }
  63. }
  64.  
  65. /* produce audio/visual effects attached to the lamps panel.
  66. */
  67. extern void FAR
  68. hud_alarm (HUD *h, OBJECT *p, int color, int mode, int hon)
  69. {
  70.     int    alarm, valarm, balarm, blink, ss2, ss3, y;
  71.     long    t;
  72.  
  73.     blink = ((int)st.present)&0x0080;    /* 128ms period */
  74.     alarm = 0;
  75.     ss2 = h->ss*2;
  76.     ss3 = h->ss*3;
  77.     y = h->orgy + h->shifty;
  78.  
  79.     if (IS_PLANE(p) && (p->gpflags & GPF_PILOT)) {
  80.         valarm = ((EX->hud & HUD_ON) && (EX->hud1 & HUD_VALARM))
  81.              || HDT_HUD == mode;
  82.         balarm = valarm && blink;
  83.  
  84.         if (EX->lamps[LAMP_GLIMIT] & LAMP_RED) {
  85.             alarm = SS_WARN;
  86.             if (balarm)
  87.                 stroke_str (h->orgx-h->dd*6, y-h->ss*5,
  88.                     "GLIMIT", ss2, color);
  89.         }
  90.  
  91.         if (EX->lamps[LAMP_STALL] & LAMP_RED) {
  92.             alarm = SS_WARN;
  93.             if (balarm)
  94.                 stroke_str (h->orgx-h->dd*5, y-ss3, "STALL",
  95.                     ss2, color);
  96.         }
  97.  
  98.         if (EX->lamps[LAMP_FUEL] & LAMP_BRED) {
  99.             alarm = SS_WARN;
  100.             if (balarm)
  101.                 stroke_str (h->orgx-h->dd*4,
  102.                     y+h->ss*5, "FUEL", ss2, color);
  103.         }
  104.  
  105.         CL->next->flags &= ~F_VISIBLE;
  106.         if (EX->lamps[LAMP_ALT] & LAMP_RED) {
  107.             if (hon && (EX->hud2 & HUD_XBREAK))
  108.                 show_xbreak (h, p, color);
  109.             if (EX->hud2 & HUD_XGRID)
  110.                 CL->next->flags |= F_VISIBLE;
  111.             if (EX->lamps[LAMP_PULLUP] & LAMP_RED) {
  112.                 alarm = SS_ALARM;
  113.                 t = 1000L * EX->fuel / EP->fuel_capacity;
  114.                 t = (t/1000)*1000+1;
  115.                 if (valarm && (st.present%t) < 200)
  116.                     stroke_str (h->orgx-h->dd*10,
  117.                         y+ss3, "PULL UP", ss3, color);
  118.             }
  119.         }
  120.  
  121.         if (EX->lamps[LAMP_EJECT] & LAMP_RED) {
  122.             alarm = SS_ALARM;
  123.             if (balarm)
  124.                 stroke_str (h->orgx-h->dd*8, y, "EJECT",
  125.                     ss3, color);
  126.         }
  127.  
  128.         if (!(EX->hud1 & HUD_AALARM))
  129.             alarm = 0;
  130.     }
  131.  
  132.     alarm_set (alarm);
  133. }
  134.